<!DOCTYPE html>
<html lang="zh-Hans">
<head>

    <!--[if lt IE 9]>
        <style>body {display: none; background: none !important} </style>
        <meta http-equiv="Refresh" Content="0; url=//outdatedbrowser.com/" />
    <![endif]-->

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no" />
<meta name="author" content="Bingo" />



<meta name="description" content="期末考试、习题、答案以及反思。">
<meta property="og:type" content="article">
<meta property="og:title" content="coursera_c++期末考试">
<meta property="og:url" content="http://blog.acbingo.cn/2016/01/27/coursera_c++期末考试/index.html">
<meta property="og:site_name" content="Bingo's Blog">
<meta property="og:description" content="期末考试、习题、答案以及反思。">
<meta property="og:updated_time" content="2016-01-27T02:56:25.806Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="coursera_c++期末考试">
<meta name="twitter:description" content="期末考试、习题、答案以及反思。">

<link rel="apple-touch-icon" href= "/apple-touch-icon.png">


    <link rel="alternate" href="/atom.xml" title="Bingo&#39;s Blog" type="application/atom+xml">



    <link rel="shortcut icon" href="/favicon.png">





    <link href="//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet">



    <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
    <link href="//cdn.bootcss.com/pace/1.0.2/themes/blue/pace-theme-minimal.css" rel="stylesheet">


<link rel="stylesheet" href="/css/style.css">



<link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">


<title>coursera_c++期末考试 | Bingo&#39;s Blog</title>

<script src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>

<script>
    var yiliaConfig = {
        fancybox: true,
        animate: false,
        isHome: false,
        isPost: true,
        isArchive: false,
        isTag: false,
        isCategory: false,
        fancybox_js: "//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.js",
        scrollreveal: "//cdn.bootcss.com/scrollReveal.js/3.1.4/scrollreveal.min.js",
        search: true
    }
</script>


    <script> yiliaConfig.jquery_ui = [false]; </script>



    <script> yiliaConfig.rootUrl = "\/";</script>






</head>
<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
    <header id="header" class="inner">
        <a href="/" class="profilepic">
            <img src="/img/avatar.png" class="animated zoomIn">
        </a>
        <hgroup>
          <h1 class="header-author"><a href="/">Bingo</a></h1>
        </hgroup>

        
        <p class="header-subtitle">Here&#39;s My Second Brains</p>
        

        
            <form id="search-form">
            <input type="text" id="local-search-input" name="q" placeholder="search..." class="search form-control" autocomplete="off" autocorrect="off" searchonload="false" />
            <i class="fa fa-times" onclick="resetSearch()"></i>
            </form>
            <div id="local-search-result"></div>
            <p class='no-result'>No results found <i class='fa fa-spinner fa-pulse'></i></p>
        


        
            <div id="switch-btn" class="switch-btn">
                <div class="icon">
                    <div class="icon-ctn">
                        <div class="icon-wrap icon-house" data-idx="0">
                            <div class="birdhouse"></div>
                            <div class="birdhouse_holes"></div>
                        </div>
                        <div class="icon-wrap icon-ribbon hide" data-idx="1">
                            <div class="ribbon"></div>
                        </div>
                        
                        <div class="icon-wrap icon-link hide" data-idx="2">
                            <div class="loopback_l"></div>
                            <div class="loopback_r"></div>
                        </div>
                        
                        
                        <div class="icon-wrap icon-me hide" data-idx="3">
                            <div class="user"></div>
                            <div class="shoulder"></div>
                        </div>
                        
                    </div>
                    
                </div>
                <div class="tips-box hide">
                    <div class="tips-arrow"></div>
                    <ul class="tips-inner">
                        <li>菜单</li>
                        <li>标签</li>
                        
                        <li>友情链接</li>
                        
                        
                        <li>关于我</li>
                        
                    </ul>
                </div>
            </div>
        

        <div id="switch-area" class="switch-area">
            <div class="switch-wrap">
                <section class="switch-part switch-part1">
                    <nav class="header-menu">
                        <ul>
                        
                            <li><a href="/">主页</a></li>
                        
                            <li><a href="/archives/">所有文章</a></li>
                        
                            <li><a href="/tags/">标签云</a></li>
                        
                            <li><a href="http://acbingo.cn/">关于我</a></li>
                        
                        </ul>
                    </nav>
                    <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" href="/&#116;&#x66;&#117;&#116;&#121;&#x40;&#x71;&#113;&#46;&#99;&#111;&#109;" title="Email"></a>
                            
                                <a class="fa GitHub" href="https://github.com/ACBingo" title="GitHub"></a>
                            
                                <a class="fa 知乎" href="https://www.zhihu.com/people/li-bing-59-10" title="知乎"></a>
                            
                                <a class="fa StackOverflow" href="http://stackoverflow.com/users/6059386/acbingo" title="StackOverflow"></a>
                            
                        </ul>
                    </nav>
                </section>
                
                
                <section class="switch-part switch-part2">
                    <div class="widget tagcloud" id="js-tagcloud">
                        <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android/">Android</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Array/">Array</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Hash-Table/">Hash Table</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/KMP/">KMP</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/LeetCode/">LeetCode</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Linked-List/">Linked List</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Math/">Math</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/STL/">STL</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/String/">String</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/android/">android</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/anroid/">anroid</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/books/">books</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/c/">c#</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/c/">c++</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cocos/">cocos</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cocos2dx/">cocos2dx</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/const/">const</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/coursera/">coursera</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/">git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/github/">github</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hash/">hash</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hdu/">hdu</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hexo/">hexo</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/markdown/">markdown</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/offer/">offer</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/other/">other</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/poj/">poj</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/shadowsocks/">shadowsocks</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/string/">string</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ubuntu/">ubuntu</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/uva/">uva</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vim/">vim</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/二分/">二分</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/二叉树/">二叉树</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/位运算/">位运算</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/其它/">其它</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/分治/">分治</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/动态规划/">动态规划</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/单调队列/">单调队列</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/回溯/">回溯</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/字符串/">字符串</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/字符串匹配/">字符串匹配</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/指针/">指针</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/排序/">排序</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/操作系统/">操作系统</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/数据结构/">数据结构</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/枚举/">枚举</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/树/">树</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/算法/">算法</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/红黑树/">红黑树</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/线段树/">线段树</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/继承/">继承</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/编译原理/">编译原理</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/虚函数/">虚函数</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/逆序对/">逆序对</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/递归/">递归</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/链表/">链表</a></li></ul>
                    </div>
                </section>
                
                
                
                <section class="switch-part switch-part3">
                    <div id="js-friends">
                    
                      <a class="main-nav-link switch-friends-link" href="https://hexo.io">Hexo</a>
                    
                      <a class="main-nav-link switch-friends-link" href="https://pages.github.com/">GitHub</a>
                    
                      <a class="main-nav-link switch-friends-link" href="http://moxfive.xyz/">MOxFIVE</a>
                    
                    </div>
                </section>
                

                
                
                <section class="switch-part switch-part4">
                
                    <div id="js-aboutme">专注于前端</div>
                </section>
                
            </div>
        </div>
    </header>                
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
      <div class="overlay">
          <div class="slider-trigger"></div>
          <h1 class="header-author js-mobile-header hide"><a href="/" title="回到主页">Bingo</a></h1>
      </div>
    <div class="intrude-less">
        <header id="header" class="inner">
            <a href="/" class="profilepic">
                <img src="/img/avatar.png" class="animated zoomIn">
            </a>
            <hgroup>
              <h1 class="header-author"><a href="/" title="回到主页">Bingo</a></h1>
            </hgroup>
            
            <p class="header-subtitle">Here&#39;s My Second Brains</p>
            
            <nav class="header-menu">
                <ul>
                
                    <li><a href="/">主页</a></li>
                
                    <li><a href="/archives/">所有文章</a></li>
                
                    <li><a href="/tags/">标签云</a></li>
                
                    <li><a href="http://acbingo.cn/">关于我</a></li>
                
                <div class="clearfix"></div>
                </ul>
            </nav>
            <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" target="_blank" href="/&#116;&#x66;&#117;&#116;&#121;&#x40;&#x71;&#113;&#46;&#99;&#111;&#109;" title="Email"></a>
                            
                                <a class="fa GitHub" target="_blank" href="https://github.com/ACBingo" title="GitHub"></a>
                            
                                <a class="fa 知乎" target="_blank" href="https://www.zhihu.com/people/li-bing-59-10" title="知乎"></a>
                            
                                <a class="fa StackOverflow" target="_blank" href="http://stackoverflow.com/users/6059386/acbingo" title="StackOverflow"></a>
                            
                        </ul>
            </nav>
        </header>                
    </div>
    <link class="menu-list" tags="标签" friends="友情链接" about="关于我"/>
</nav>
      <div class="body-wrap"><article id="post-coursera_c++期末考试" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/2016/01/27/coursera_c++期末考试/" class="article-date">
      <time datetime="2016-01-27T02:40:52.000Z" itemprop="datePublished">2016-01-27</time>
</a>


    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      coursera_c++期末考试
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        

        
    <div class="article-tag tagcloud">
        <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/coursera/">coursera</a></li></ul>
    </div>

        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
          
        <p>期末考试、习题、答案以及反思。<br><a id="more"></a></p>
<h1 id="编程题＃1：输出200"><a href="#编程题＃1：输出200" class="headerlink" title="编程题＃1：输出200"></a>编程题＃1：输出200</h1><p>来源: 北京大学在线程序评测系统POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>总时间限制: 1000ms 内存限制: 1024kB</p>
<p>描述</p>
<p>使以下代码输出结果为200.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">#include&lt;iostream&gt;</div><div class="line">using namespace std;</div><div class="line">class Number &#123;</div><div class="line">public:</div><div class="line">    int num;</div><div class="line">    Number(int n=0): num(n) &#123;&#125;</div><div class="line">// 在此处补充你的代码</div><div class="line">&#125;;</div><div class="line"></div><div class="line">int main() &#123;</div><div class="line">    Number n1(10), n2(20);</div><div class="line">    Number n3;n3 = n1*n2;</div><div class="line">    cout &lt;&lt; int(n3) &lt;&lt; endl;</div><div class="line">    return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">输入</div><div class="line"></div><div class="line">不需要输入。</div><div class="line"></div><div class="line">输出</div><div class="line"></div><div class="line">输出结果为200。</div><div class="line"></div><div class="line">样例输入</div><div class="line"></div><div class="line">不需要输入。</div><div class="line">样例输出</div><div class="line"></div><div class="line">200</div></pre></td></tr></table></figure>
<h2 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">Number operator *( Number const &amp; n2)</div><div class="line">	&#123;</div><div class="line">		return Number(this-&gt;num*n2.num);</div><div class="line">	&#125;</div><div class="line">	operator int()</div><div class="line">	&#123;</div><div class="line">		return this-&gt;num;</div><div class="line">	&#125;</div></pre></td></tr></table></figure>
<p>考察自定义强制类型转换。<br>重载格式如下<br>operator int()<br>无返回值，无参数</p>
<h1 id="编程题＃2：输出指定结果一"><a href="#编程题＃2：输出指定结果一" class="headerlink" title="编程题＃2：输出指定结果一"></a>编程题＃2：输出指定结果一</h1><p>来源: 北京大学在线程序评测系统POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>总时间限制: 1000ms 内存限制: 1024kB</p>
<p>描述</p>
<p>填写代码，使输出结果为</p>
<p>2</p>
<p>2</p>
<p>8</p>
<p>10<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line">#include &lt;iostream&gt;</div><div class="line">using namespace std;</div><div class="line">class Number &#123;</div><div class="line">public:</div><div class="line">    int num;</div><div class="line">    Number(int n): num(n) &#123;</div><div class="line">    &#125;</div><div class="line">// 在此处补充你的代码</div><div class="line">&#125;;</div><div class="line">int main() &#123;</div><div class="line">    Number a(2);</div><div class="line">    Number b = a;</div><div class="line">    cout &lt;&lt; a.value() &lt;&lt; endl;</div><div class="line">    cout &lt;&lt; b.value() &lt;&lt; endl;</div><div class="line">    a.value() = 8;</div><div class="line">    cout &lt;&lt; a.value() &lt;&lt; endl;</div><div class="line">    a+b;</div><div class="line">    cout &lt;&lt; a.value() &lt;&lt; endl;</div><div class="line">    return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line">输入</div><div class="line"></div><div class="line">不需要输入。</div><div class="line"></div><div class="line">输出</div><div class="line"></div><div class="line">使输出结果为</div><div class="line"></div><div class="line">2</div><div class="line"></div><div class="line">2</div><div class="line"></div><div class="line">8</div><div class="line"></div><div class="line">10</div><div class="line"></div><div class="line">样例输入</div><div class="line"></div><div class="line">不需要输入。</div><div class="line">样例输出</div><div class="line"></div><div class="line">2</div><div class="line">2</div><div class="line">8</div><div class="line">10</div></pre></td></tr></table></figure>
<h2 id="代码-1"><a href="#代码-1" class="headerlink" title="代码"></a>代码</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">int&amp; value()</div><div class="line">	&#123;</div><div class="line">		return num;</div><div class="line">	&#125;</div><div class="line">	void operator+(Number const&amp; i)</div><div class="line">	&#123;</div><div class="line">		this-&gt;num += i.num;</div><div class="line">	&#125;</div></pre></td></tr></table></figure>
<p>重载+号</p>
<h1 id="编程题＃3：计算数列平方和"><a href="#编程题＃3：计算数列平方和" class="headerlink" title="编程题＃3：计算数列平方和"></a>编程题＃3：计算数列平方和</h1><p>来源: 北京大学在线程序评测系统POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>总时间限制: 1000ms 内存限制: 1024kB</p>
<p>描述</p>
<p>请写出sum函数，使其可以计算输入数列的平方和。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">#include &lt;iostream&gt;</div><div class="line">using namespace std;</div><div class="line">// 在此处补充你的代码</div><div class="line">int sqr(int n) &#123;</div><div class="line">    return n * n;</div><div class="line">&#125;</div><div class="line">int main() &#123;</div><div class="line">    int t, n, a[0x100];</div><div class="line">    cin &gt;&gt; t;</div><div class="line">    for (int c = 0; c &lt; t; ++c) &#123;</div><div class="line">        cin &gt;&gt; n;</div><div class="line">    for (int i = 0; i &lt; n; ++i) cin &gt;&gt; a[i];</div><div class="line">    cout &lt;&lt; sum(a, n, sqr) &lt;&lt; endl;</div><div class="line">    &#125;</div><div class="line">    return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line">输入</div><div class="line"></div><div class="line">第一行是一个整数 t (t &lt;= 10)，表示数据组数；</div><div class="line"></div><div class="line">每组输入数据包含两行，第一行是一个整数 n (n &lt;= 100)，</div><div class="line"></div><div class="line">第二行是 n 个用空格分隔开的整数</div><div class="line"></div><div class="line">输出</div><div class="line"></div><div class="line">对每组输入数据，输出该组数据中 n 个整数的平方和</div><div class="line"></div><div class="line">样例输入</div><div class="line"></div><div class="line">2</div><div class="line">2</div><div class="line">4 3</div><div class="line">3</div><div class="line">0 1 2</div><div class="line">样例输出</div><div class="line"></div><div class="line">25</div><div class="line">5</div></pre></td></tr></table></figure>
<h2 id="代码-2"><a href="#代码-2" class="headerlink" title="代码"></a>代码</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">int sum(int* a, int n, int (*op)(int))</div><div class="line">&#123;</div><div class="line">	int ans = 0;</div><div class="line">	for (int i = 0; i &lt; n; i++) &#123;</div><div class="line">		ans += (*op)(a[i]);</div><div class="line">	&#125;</div><div class="line">	return ans;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>考察函数名作为参数的传递。<br>int （<em>op）(int,int)
</em>op即为函数名</p>
<h1 id="编程题＃4：计算整数平方和"><a href="#编程题＃4：计算整数平方和" class="headerlink" title="编程题＃4：计算整数平方和"></a>编程题＃4：计算整数平方和</h1><p>来源: 北京大学在线程序评测系统POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>总时间限制: 1000ms 内存限制: 1024kB</p>
<p>描述</p>
<p>下列程序每次读入一个整数N，若N为0则退出，否则输出N和N的平方。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">#include &lt;iostream&gt;</div><div class="line">using namespace std;</div><div class="line">// 在此处补充你的代码</div><div class="line">int main(int argc, char* argv[]) &#123;</div><div class="line">        CType obj;</div><div class="line">        int n;</div><div class="line">        cin&gt;&gt;n;</div><div class="line">        while ( n ) &#123;</div><div class="line">                obj.setvalue(n);</div><div class="line">                cout&lt;&lt;obj++&lt;&lt;&quot; &quot;&lt;&lt;obj&lt;&lt;endl;</div><div class="line">                cin&gt;&gt;n;</div><div class="line">        &#125;</div><div class="line">        return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line">输入</div><div class="line"></div><div class="line">K个整数。除最后一个数据外，其他数据均不为0。</div><div class="line"></div><div class="line">输出</div><div class="line"></div><div class="line">K-1行。第I行输出第I个输入数和它的平方。</div><div class="line"></div><div class="line">样例输入</div><div class="line"></div><div class="line">1 5 8 9 0</div><div class="line">样例输出</div><div class="line"></div><div class="line">1 1</div><div class="line">5 25</div><div class="line">8 64</div><div class="line">9 81</div></pre></td></tr></table></figure>
<h2 id="代码-3"><a href="#代码-3" class="headerlink" title="代码"></a>代码</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">class CType &#123;</div><div class="line">	int n;</div><div class="line">public:</div><div class="line">	void setvalue(int t)</div><div class="line">	&#123;</div><div class="line">		n = t;</div><div class="line">	&#125;</div><div class="line">	//输入输出运算符只能用友元函数重载</div><div class="line">	friend ostream &amp;operator&lt;&lt;(ostream &amp;os, const CType &amp;c);</div><div class="line">	int operator++(int)</div><div class="line">	&#123;</div><div class="line">		return n;</div><div class="line">	&#125;</div><div class="line">&#125;;</div><div class="line">ostream &amp;operator&lt;&lt;(ostream &amp;os, const CType &amp;c)</div><div class="line">&#123;</div><div class="line">	os &lt;&lt; c.n*c.n;</div><div class="line">	return os;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>考察&lt;&lt;运算符的重载，<br>只能重载为友元函数<br>ostream &amp;operator&lt;&lt;(ostream &amp;os, const CType &amp;c)<br>{<br>    os &lt;&lt; c.n*c.n;<br>    return os;<br>}<br>对于“++” 和“–”这两个一元运算符，存在前置和后置的问题，在定义时必须有所区分。<br>（1） 用成员函数的形式来进行重载<br>如果++为前增量运算符时，重载函数的一般格式为：<br>&lt; type &gt; ClassName :: operator ++ ( )<br>{<br> //…<br>}</p>
<p>如果++为后增量运算符时，重载函数的一般格式为：<br>&lt; type &gt; ClassName :: operator ++ ( int  )<br>{<br> //…<br>}</p>
<p>(2) 非成员函数形式的重载<br>以++ 为例说明<br>用友元函数来实现“++”运算符的重载时，前置++运算符的重载的一般格式：<br>friend <type> operator ++ (ClassName &amp; );<br>其中，第一个参数是要实现++运算的对象。</type></p>
<p>后置++运算符的重载的一般格式：<br>friend <type> operator ++(ClassName &amp;,int);<br>其中，第一个参数是要实现++运算的对象；而第二个参数除了用于区分是后置运算外，并没有其他意义，故起参数可有可无</type></p>
<h1 id="编程题＃5：计算数组的低3位之和"><a href="#编程题＃5：计算数组的低3位之和" class="headerlink" title="编程题＃5：计算数组的低3位之和"></a>编程题＃5：计算数组的低3位之和</h1><p>来源: 北京大学在线程序评测系统POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>总时间限制: 1000ms 内存限制: 1024kB</p>
<p>描述</p>
<p>输入一个正整数构成的数组a[0], a[1], a[2], … , a[n-1], 计算它们的二进制低3位之和。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line">#include &lt;iostream&gt;</div><div class="line">#include &lt;vector&gt;</div><div class="line">#include &lt;algorithm&gt;</div><div class="line">using namespace std;</div><div class="line">// 在此处补充你的代码</div><div class="line">int main(int argc, char* argv[]) &#123;</div><div class="line">        int v, my_sum=0;</div><div class="line">        vector&lt;int&gt; vec;</div><div class="line">        cin&gt;&gt;v;</div><div class="line">        while ( v ) &#123;</div><div class="line">                vec.push_back(v);</div><div class="line">                cin&gt;&gt;v;</div><div class="line">        &#125;</div><div class="line">        for_each(vec.begin(), vec.end(), CMy_add(my_sum));</div><div class="line">        cout&lt;&lt;my_sum&lt;&lt;endl;</div><div class="line">        return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">输入</div><div class="line"></div><div class="line">数组a,以0表示输入结束。</div><div class="line"></div><div class="line">输出</div><div class="line"></div><div class="line">一个整数 , 所输入数组各元素的二进制低3位之和。</div><div class="line"></div><div class="line">样例输入</div><div class="line"></div><div class="line">1 3 9 7 3 6 20 15 18 17 4 8 18 0</div><div class="line">样例输出</div><div class="line"></div><div class="line">41</div><div class="line">## 代码</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">class CMy_add</div><div class="line">&#123;</div><div class="line">	int &amp;sum;</div><div class="line">public:</div><div class="line">	CMy_add(int &amp;n) :sum(n) &#123;&#125;</div><div class="line">	int operator()(int x)</div><div class="line">	&#123;</div><div class="line">		while (x &gt;= 8) &#123;</div><div class="line">			x -= 8;</div><div class="line">		&#125;</div><div class="line">		sum += x;</div><div class="line">	&#125;</div><div class="line">&#125;;</div></pre></td></tr></table></figure>
<p>考察函数对象。此题不会。<br>这节课没好好听= =</p>
<h1 id="编程题＃6：MyString"><a href="#编程题＃6：MyString" class="headerlink" title="编程题＃6：MyString"></a>编程题＃6：MyString</h1><p>来源: 北京大学在线程序评测系统POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>总时间限制: 1000ms 内存限制: 1024kB</p>
<p>描述</p>
<p>请写出 MyString类，使得下面程序的输出结果符合下面的要求。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div></pre></td><td class="code"><pre><div class="line">#include &lt;cstring&gt;</div><div class="line">#include &lt;cstdlib&gt;</div><div class="line">#include &lt;string&gt;</div><div class="line">#include &lt;iostream&gt;</div><div class="line">using namespace std;</div><div class="line">// 在此处补充你的代码</div><div class="line">int CompareString( const void * e1, const void * e2)</div><div class="line">&#123;</div><div class="line">        MyString * s1 = (MyString * ) e1;</div><div class="line">        MyString * s2 = (MyString * ) e2;</div><div class="line">        if( * s1 &lt; *s2 )</div><div class="line">                 return -1;</div><div class="line">        else if( *s1 == *s2)</div><div class="line">                 return 0;</div><div class="line">        else if( *s1 &gt; *s2 )</div><div class="line">                 return 1;</div><div class="line">&#125;</div><div class="line">int main()</div><div class="line">&#123;</div><div class="line">        MyString s1(&quot;abcd-&quot;),s2,s3(&quot;efgh-&quot;),s4(s1);</div><div class="line">        MyString SArray[4] = &#123;&quot;big&quot;,&quot;me&quot;,&quot;about&quot;,&quot;take&quot;&#125;;</div><div class="line">        cout &lt;&lt; &quot;1. &quot; &lt;&lt; s1 &lt;&lt; s2 &lt;&lt; s3&lt;&lt; s4&lt;&lt; endl;</div><div class="line">        s4 = s3;</div><div class="line">        s3 = s1 + s3;</div><div class="line">        cout &lt;&lt; &quot;2. &quot; &lt;&lt; s1 &lt;&lt; endl;</div><div class="line">        cout &lt;&lt; &quot;3. &quot; &lt;&lt; s2 &lt;&lt; endl;</div><div class="line">        cout &lt;&lt; &quot;4. &quot; &lt;&lt; s3 &lt;&lt; endl;</div><div class="line">        cout &lt;&lt; &quot;5. &quot; &lt;&lt; s4 &lt;&lt; endl;</div><div class="line">        cout &lt;&lt; &quot;6. &quot; &lt;&lt; s1[2] &lt;&lt; endl;</div><div class="line">        s2 = s1;</div><div class="line">        s1 = &quot;ijkl-&quot;;</div><div class="line">        s1[2] = &apos;A&apos; ;</div><div class="line">        cout &lt;&lt; &quot;7. &quot; &lt;&lt; s2 &lt;&lt; endl;</div><div class="line">        cout &lt;&lt; &quot;8. &quot; &lt;&lt; s1 &lt;&lt; endl;</div><div class="line">        s1 += &quot;mnop&quot;;</div><div class="line">        cout &lt;&lt; &quot;9. &quot; &lt;&lt; s1 &lt;&lt; endl;</div><div class="line">        s4 = &quot;qrst-&quot; + s2;</div><div class="line">        cout &lt;&lt; &quot;10. &quot; &lt;&lt; s4 &lt;&lt; endl;</div><div class="line">        s1 = s2 + s4 + &quot; uvw &quot; + &quot;xyz&quot;;</div><div class="line">        cout &lt;&lt; &quot;11. &quot; &lt;&lt; s1 &lt;&lt; endl;</div><div class="line">        qsort(SArray,4,sizeof(MyString),CompareString);</div><div class="line">        for( int i = 0;i &lt; 4;i ++ )</div><div class="line">        cout &lt;&lt; SArray[i] &lt;&lt; endl;</div><div class="line">        //s1的从下标0开始长度为4的子串</div><div class="line">        cout &lt;&lt; s1(0,4) &lt;&lt; endl;</div><div class="line">        //s1的从下标5开始长度为10的子串</div><div class="line">        cout &lt;&lt; s1(5,10) &lt;&lt; endl;</div><div class="line">        return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>输入</p>
<p>无</p>
<p>输出<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div></pre></td><td class="code"><pre><div class="line">1. abcd-efgh-abcd-</div><div class="line"></div><div class="line">2. abcd-</div><div class="line"></div><div class="line">3.</div><div class="line"></div><div class="line">4. abcd-efgh-</div><div class="line"></div><div class="line">5. efgh-</div><div class="line"></div><div class="line">6. c</div><div class="line"></div><div class="line">7. abcd-</div><div class="line"></div><div class="line">8. ijAl-</div><div class="line"></div><div class="line">9. ijAl-mnop</div><div class="line"></div><div class="line">10. qrst-abcd-</div><div class="line"></div><div class="line">11. abcd-qrst-abcd- uvw xyz</div><div class="line"></div><div class="line">about</div><div class="line"></div><div class="line">big</div><div class="line"></div><div class="line">me</div><div class="line"></div><div class="line">take</div><div class="line"></div><div class="line">abcd</div><div class="line"></div><div class="line">qrst-abcd-</div></pre></td></tr></table></figure></p>
<p>样例输入</p>
<p>无<br>样例输出<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line">1. abcd-efgh-abcd-</div><div class="line">2. abcd-</div><div class="line">3.</div><div class="line">4. abcd-efgh-</div><div class="line">5. efgh-</div><div class="line">6. c</div><div class="line">7. abcd-</div><div class="line">8. ijAl-</div><div class="line">9. ijAl-mnop</div><div class="line">10. qrst-abcd-</div><div class="line">11. abcd-qrst-abcd- uvw xyz</div><div class="line">about</div><div class="line">big</div><div class="line">me</div><div class="line">take</div><div class="line">abcd</div><div class="line">qrst-abcd-</div></pre></td></tr></table></figure></p>
<h2 id="代码-4"><a href="#代码-4" class="headerlink" title="代码"></a>代码</h2><p>考察各种运算符重载，这题出的很全啊。</p>
<p>不过尼玛原来只是继承string就行了啊啊啊啊啊啊啊啊啊啊<br>害我完全自己写了MyString类</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div><div class="line">137</div><div class="line">138</div><div class="line">139</div><div class="line">140</div><div class="line">141</div><div class="line">142</div><div class="line">143</div><div class="line">144</div><div class="line">145</div><div class="line">146</div><div class="line">147</div><div class="line">148</div><div class="line">149</div><div class="line">150</div><div class="line">151</div><div class="line">152</div><div class="line">153</div><div class="line">154</div><div class="line">155</div><div class="line">156</div><div class="line">157</div><div class="line">158</div><div class="line">159</div><div class="line">160</div><div class="line">161</div><div class="line">162</div><div class="line">163</div><div class="line">164</div></pre></td><td class="code"><pre><div class="line">#include &lt;cstring&gt;</div><div class="line">#include &lt;cstdlib&gt;</div><div class="line">#include &lt;string&gt;</div><div class="line">#include &lt;iostream&gt;</div><div class="line">using namespace std;</div><div class="line">class MyString :public string &#123;</div><div class="line">public:</div><div class="line">	MyString() :string() &#123;&#125;;</div><div class="line">	MyString(const char *s) :string(s) &#123;&#125;;</div><div class="line">	MyString(const string &amp;s) :string(s) &#123;&#125;;</div><div class="line">	MyString operator()(int i, int j) &#123;</div><div class="line">		return this-&gt;substr(i, j);</div><div class="line">	&#125;</div><div class="line">&#125;;</div><div class="line">// 在此处补充你的代码</div><div class="line">//class MyString</div><div class="line">//&#123;</div><div class="line">//	string s;</div><div class="line">//public:</div><div class="line">//	MyString() &#123;&#125;</div><div class="line">//	MyString(string t) :s(t) &#123;&#125;</div><div class="line">//	MyString(const char* t)</div><div class="line">//	&#123;</div><div class="line">//		string st;</div><div class="line">//		for (int i = 0; t[i] != &apos;\0&apos;; i++)</div><div class="line">//			st += t[i];</div><div class="line">//		s = st;</div><div class="line">//	&#125;</div><div class="line">//	MyString(const MyString&amp; t)</div><div class="line">//	&#123;</div><div class="line">//		//cout &lt;&lt; &quot;yes&quot; &lt;&lt; endl;</div><div class="line">//		this-&gt;s = t.s;</div><div class="line">//	&#125;</div><div class="line">//	bool operator&lt;(MyString &amp;s2)</div><div class="line">//	&#123;</div><div class="line">//		return this-&gt;s &lt; s2.s;</div><div class="line">//	&#125;</div><div class="line">//	bool operator==(MyString &amp;s2)</div><div class="line">//	&#123;</div><div class="line">//		return this-&gt;s == s2.s;</div><div class="line">//	&#125;</div><div class="line">//	bool operator&gt;(MyString &amp;s2)</div><div class="line">//	&#123;</div><div class="line">//		return this-&gt;s &gt; s2.s;</div><div class="line">//	&#125;</div><div class="line">//	friend ostream &amp; operator&lt;&lt;(ostream &amp;os, const MyString &amp;t);</div><div class="line">//	char &amp; operator[](int i)</div><div class="line">//	&#123;</div><div class="line">//		return this-&gt;s[i];</div><div class="line">//	&#125;</div><div class="line">//	MyString operator+(MyString const &amp;t)</div><div class="line">//	&#123;</div><div class="line">//		MyString p;</div><div class="line">//		p.s = this-&gt;s + t.s;</div><div class="line">//		return p;</div><div class="line">//	&#125;</div><div class="line">//	MyString operator=(string t)</div><div class="line">//	&#123;</div><div class="line">//		this-&gt;s = t;</div><div class="line">//		return *this;</div><div class="line">//	&#125;</div><div class="line">//	MyString operator=(char *t)</div><div class="line">//	&#123;</div><div class="line">//		string st;</div><div class="line">//		for (int i = 0; t[i] != &apos;\0&apos;; i++)</div><div class="line">//			st += t[i];</div><div class="line">//		this-&gt;s = st;</div><div class="line">//		return *this;</div><div class="line">//	&#125;</div><div class="line">//	char operator=(char t)</div><div class="line">//	&#123;</div><div class="line">//		return t;</div><div class="line">//	&#125;</div><div class="line">//	MyString&amp; operator+=(string t)</div><div class="line">//	&#123;</div><div class="line">//		this-&gt;s += t;</div><div class="line">//		return *this;</div><div class="line">//	&#125;</div><div class="line">//	friend MyString&amp; operator+(string t, MyString &amp;st);</div><div class="line">//	friend MyString&amp; operator+(char *t, MyString &amp;st);</div><div class="line">//	MyString&amp; operator+(string t)</div><div class="line">//	&#123;</div><div class="line">//		this-&gt;s += t;</div><div class="line">//		return *this;</div><div class="line">//	&#125;</div><div class="line">//	MyString&amp; operator+(char* t)</div><div class="line">//	&#123;</div><div class="line">//		string st;</div><div class="line">//		for (int i = 0; t[i] != &apos;\0&apos;; i++)</div><div class="line">//			st += t[i];</div><div class="line">//</div><div class="line">//		this-&gt;s += st;</div><div class="line">//		return *this;</div><div class="line">//	&#125;</div><div class="line">//	string operator()(int p, int len)</div><div class="line">//	&#123;</div><div class="line">//		return this-&gt;s.substr(p, len);</div><div class="line">//	&#125;</div><div class="line">//&#125;;</div><div class="line">//MyString&amp; operator+(string t,  MyString  &amp;st)</div><div class="line">//&#123;</div><div class="line">//	MyString p(t + st.s);</div><div class="line">//	return p;</div><div class="line">//&#125;</div><div class="line">//MyString&amp; operator+(char* t, MyString  &amp;st)</div><div class="line">//&#123;</div><div class="line">//	string stp;</div><div class="line">//	for (int i = 0; t[i] != &apos;\0&apos;; i++)</div><div class="line">//		stp += t[i];</div><div class="line">//	MyString p(t + st.s);</div><div class="line">//	return p;</div><div class="line">//&#125;</div><div class="line">//ostream &amp; operator&lt;&lt;(ostream &amp;os, const MyString &amp;t)</div><div class="line">//&#123;</div><div class="line">//	os &lt;&lt; t.s;</div><div class="line">//	return os;</div><div class="line">//&#125;</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line">int CompareString(const void * e1, const void * e2)</div><div class="line">&#123;</div><div class="line">	MyString * s1 = (MyString *)e1;</div><div class="line">	MyString * s2 = (MyString *)e2;</div><div class="line">	if (*s1 &lt; *s2)</div><div class="line">		return -1;</div><div class="line">	else if (*s1 == *s2)</div><div class="line">		return 0;</div><div class="line">	else if (*s1 &gt; *s2)</div><div class="line">		return 1;</div><div class="line">&#125;</div><div class="line">int main()</div><div class="line">&#123;</div><div class="line">	MyString s1(&quot;abcd-&quot;), s2, s3(&quot;efgh-&quot;), s4(s1);</div><div class="line">	MyString SArray[4] = &#123; &quot;big&quot;,&quot;me&quot;,&quot;about&quot;,&quot;take&quot; &#125;;</div><div class="line">	cout &lt;&lt; &quot;1. &quot; &lt;&lt; s1 &lt;&lt; s2 &lt;&lt; s3 &lt;&lt; s4 &lt;&lt; endl;</div><div class="line">	s4 = s3;</div><div class="line">	s3 = s1 + s3;</div><div class="line">	cout &lt;&lt; &quot;2. &quot; &lt;&lt; s1 &lt;&lt; endl;</div><div class="line">	cout &lt;&lt; &quot;3. &quot; &lt;&lt; s2 &lt;&lt; endl;</div><div class="line">	cout &lt;&lt; &quot;4. &quot; &lt;&lt; s3 &lt;&lt; endl;</div><div class="line">	cout &lt;&lt; &quot;5. &quot; &lt;&lt; s4 &lt;&lt; endl;</div><div class="line">	cout &lt;&lt; &quot;6. &quot; &lt;&lt; s1[2] &lt;&lt; endl;</div><div class="line">	s2 = s1;</div><div class="line">	s1 = &quot;ijkl-&quot;;</div><div class="line">	s1[2] = &apos;A&apos;;</div><div class="line">	cout &lt;&lt; &quot;7. &quot; &lt;&lt; s2 &lt;&lt; endl;</div><div class="line">	cout &lt;&lt; &quot;8. &quot; &lt;&lt; s1 &lt;&lt; endl;</div><div class="line">	s1 += &quot;mnop&quot;;</div><div class="line">	cout &lt;&lt; &quot;9. &quot; &lt;&lt; s1 &lt;&lt; endl;</div><div class="line">	s4 = &quot;qrst-&quot; + s2;</div><div class="line">	cout &lt;&lt; &quot;10. &quot; &lt;&lt; s4 &lt;&lt; endl;</div><div class="line">	s1 = s2 + s4 + &quot; uvw &quot; + &quot;xyz&quot;;</div><div class="line">	cout &lt;&lt; &quot;11. &quot; &lt;&lt; s1 &lt;&lt; endl;</div><div class="line">	qsort(SArray, 4, sizeof(MyString), CompareString);</div><div class="line">	for (int i = 0; i &lt; 4; i++)</div><div class="line">		cout &lt;&lt; SArray[i] &lt;&lt; endl;</div><div class="line">	//s1的从下标0开始长度为4的子串</div><div class="line">	cout &lt;&lt; s1(0, 4) &lt;&lt; endl;</div><div class="line">	//s1的从下标5开始长度为10的子串</div><div class="line">	cout &lt;&lt; s1(5, 10) &lt;&lt; endl;</div><div class="line">	system(&quot;pause&quot;);</div><div class="line">	return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h1 id="编程题＃7：字符串排序"><a href="#编程题＃7：字符串排序" class="headerlink" title="编程题＃7：字符串排序"></a>编程题＃7：字符串排序</h1><p>来源: 北京大学在线程序评测系统POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>总时间限制: 1000ms 内存限制: 1024kB</p>
<p>描述</p>
<p>请按照要求对输入的字符串进行排序。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div></pre></td><td class="code"><pre><div class="line">#include &lt;iostream&gt;</div><div class="line">#include &lt;string&gt;</div><div class="line">#include &lt;list&gt;</div><div class="line">using namespace std;</div><div class="line"></div><div class="line">class A&#123;</div><div class="line">private:</div><div class="line">        string name;</div><div class="line">public:</div><div class="line">        A(string n) :name(n)&#123;&#125;</div><div class="line">        friend bool operator &lt; (const class A&amp; a1, const class A &amp;a2);</div><div class="line">        friend bool operator == (const class A &amp;a1, const class A &amp;a2)&#123;</div><div class="line">                if (a1.name.size() == a2.name.size())</div><div class="line">                        return true;</div><div class="line">                else</div><div class="line">                        return false;</div><div class="line">        &#125;</div><div class="line">        friend ostream &amp; operator &lt;&lt; (ostream &amp;o, const A &amp;a)&#123;</div><div class="line">                o &lt;&lt; a.name;</div><div class="line">                return o;</div><div class="line">        &#125;</div><div class="line">        string get_name() const&#123;</div><div class="line">                return name;</div><div class="line">        &#125;</div><div class="line">        int get_size() const&#123;</div><div class="line">                return name.size();</div><div class="line">        &#125;</div><div class="line">&#125;;</div><div class="line">// 在此处补充你的代码</div><div class="line">int main(int argc, char* argv[])</div><div class="line">&#123;</div><div class="line">        list&lt;A&gt; lst;</div><div class="line">        int ncase, n, i = 1;</div><div class="line">        string s;</div><div class="line">        cin &gt;&gt; ncase;</div><div class="line">        while (ncase--)&#123;</div><div class="line">                cout &lt;&lt; &quot;Case: &quot;&lt;&lt;i++ &lt;&lt; endl;</div><div class="line">                cin &gt;&gt; n;</div><div class="line">                for (int i = 0; i &lt; n; i++)&#123;</div><div class="line">                         cin &gt;&gt; s;</div><div class="line">                         lst.push_back(A(s));</div><div class="line">                &#125;</div><div class="line">                lst.sort();</div><div class="line">                Show(lst.begin(), lst.end(), Print());</div><div class="line"></div><div class="line">                cout &lt;&lt; endl;</div><div class="line">                lst.sort(MyLarge&lt;A&gt;());</div><div class="line">                Show(lst.begin(), lst.end(), Print());</div><div class="line">                cout &lt;&lt; endl;</div><div class="line">                lst.clear();</div><div class="line">        &#125;</div><div class="line">        return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div></pre></td><td class="code"><pre><div class="line">输入</div><div class="line"></div><div class="line">第一行是正整数T，表示测试数据的组数</div><div class="line"></div><div class="line">每组测试数据输入共两行，</div><div class="line"></div><div class="line">第一行是正整数N，表示字符串个数</div><div class="line"></div><div class="line">第二行是N个字符串, 字符串间用空格分离</div><div class="line"></div><div class="line">输出</div><div class="line"></div><div class="line">对于每组测试数据，先输出一行：</div><div class="line"></div><div class="line">Case: n</div><div class="line"></div><div class="line">如对第一组数据就输出Case: 1</div><div class="line"></div><div class="line">第二行按照字符串长度从小到大排序之后输出N个字符串，字符串之间以空格间隔（不会出现字符串长度相同的情况）</div><div class="line"></div><div class="line">第三行按照字符串首字符ASCII码序从小到大排序之后输出N个字符串，字符串之间以空格间隔（不会出现字符串首字母相同的情况）</div><div class="line"></div><div class="line">样例输入</div><div class="line"></div><div class="line">2</div><div class="line">4</div><div class="line">a bnss ds tsdfasg</div><div class="line">5</div><div class="line">aaa bbbb ccccd sa q</div><div class="line">样例输出</div><div class="line"></div><div class="line">Case: 1</div><div class="line">a ds bnss tsdfasg</div><div class="line">a bnss ds tsdfasg</div><div class="line">Case: 2</div><div class="line">q sa aaa bbbb ccccd</div><div class="line">aaa bbbb ccccd q sa</div></pre></td></tr></table></figure>
<h2 id="代码-5"><a href="#代码-5" class="headerlink" title="代码"></a>代码</h2><p>考察函数对象这一块。。。看样子是得回头好好看看了= =这题自己一点头绪没有<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div></pre></td><td class="code"><pre><div class="line">bool operator&lt; (const A&amp; a1, const A &amp;a2) &#123;</div><div class="line">	return a1.name.size() &lt; a2.name.size();</div><div class="line">&#125;;</div><div class="line"></div><div class="line">template &lt;class Iterator, class Function&gt;</div><div class="line">void Show(Iterator begin, Iterator end, Function print) &#123;</div><div class="line">	for (Iterator iterator1 = begin; iterator1 != end; iterator1++) &#123;</div><div class="line">		print(*iterator1);</div><div class="line">	&#125;</div><div class="line">&#125;;</div><div class="line"></div><div class="line">class Print &#123;</div><div class="line">public:</div><div class="line">	void operator()(const A &amp;a) &#123;</div><div class="line">		cout &lt;&lt; a.get_name() &lt;&lt; &quot; &quot;;</div><div class="line">	&#125;</div><div class="line">&#125;;</div><div class="line"></div><div class="line">template &lt;class A&gt;</div><div class="line">struct MyLarge &#123;</div><div class="line">	inline bool operator()(const A &amp;a1, const A &amp;a2) &#123;</div><div class="line">		return a1.get_name() &lt; a2.get_name();</div><div class="line">	&#125;</div><div class="line">&#125;;</div></pre></td></tr></table></figure></p>
<h1 id="编程题＃8：计算整数k"><a href="#编程题＃8：计算整数k" class="headerlink" title="编程题＃8：计算整数k"></a>编程题＃8：计算整数k</h1><p>来源: 北京大学在线程序评测系统POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>总时间限制: 1000ms 内存限制: 1024kB</p>
<p>描述</p>
<p>输入整数 n ( 0 &lt;=n&lt;= 2^30) , 以及整数i,j(0 &lt;= i,j &lt;31,i &lt; j-1), 输出整数k(按十六进制输出结果 )，k的第i位和n相同，第j位和n不同，i,j之间的位是1, 其他位都是0。这里提到的所有的位，指的都是二进制位，最右边算第0位。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">输入</div><div class="line"></div><div class="line">第一行是整数 t，表示数据组数。</div><div class="line"></div><div class="line">每组输入数据是一行，三个整数 n,i和j。</div><div class="line"></div><div class="line">输出</div><div class="line"></div><div class="line">对每组输入数据，按十六进制输出结果。</div><div class="line"></div><div class="line">样例输入</div><div class="line"></div><div class="line">2</div><div class="line">23 3 5</div><div class="line">7 0 2</div><div class="line">样例输出</div><div class="line"></div><div class="line">30</div><div class="line">3</div></pre></td></tr></table></figure>
<p>提示</p>
<p>本题请写出完整的程序。</p>
<h2 id="代码-6"><a href="#代码-6" class="headerlink" title="代码"></a>代码</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line">#include &lt;bitset&gt;</div><div class="line">#include &lt;iostream&gt;</div><div class="line">using namespace std;</div><div class="line">int main()</div><div class="line">&#123;</div><div class="line">	int kkk;</div><div class="line">	cin &gt;&gt; kkk;</div><div class="line">	while (kkk--) &#123;</div><div class="line">		int n, i, j;</div><div class="line">		cin &gt;&gt; n &gt;&gt; i &gt;&gt; j;</div><div class="line">		bitset&lt;50&gt; p;</div><div class="line">		bitset&lt;50&gt; t(n);</div><div class="line">		p[i] = t[i];</div><div class="line">		p[j] = !t[j];</div><div class="line">		for (int k = i + 1; k &lt; j; k++)</div><div class="line">			p[k] = 1;</div><div class="line">		//cout &lt;&lt; p &lt;&lt; endl;</div><div class="line">		int ans = p.to_ulong();</div><div class="line">		cout &lt;&lt; hex &lt;&lt; ans &lt;&lt; endl;</div><div class="line">	&#125;</div><div class="line">	return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>考察bitset,甚是好用呀。</p>
<h1 id="编程题＃9：人群的排序和分类"><a href="#编程题＃9：人群的排序和分类" class="headerlink" title="编程题＃9：人群的排序和分类"></a>编程题＃9：人群的排序和分类</h1><p>来源: 北京大学在线程序评测系统POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>总时间限制: 1000ms 内存限制: 1024kB</p>
<p>描述</p>
<p>对人群按照输入的信息进行排序和分类。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div></pre></td><td class="code"><pre><div class="line">#include &lt;iostream&gt;</div><div class="line">#include &lt;set&gt;</div><div class="line">#include &lt;iterator&gt;</div><div class="line">#include &lt;algorithm&gt;</div><div class="line">using namespace std;</div><div class="line">// 在此处补充你的代码</div><div class="line">int main()</div><div class="line">&#123;</div><div class="line"></div><div class="line">        int t;</div><div class="line">        cin &gt;&gt; t;</div><div class="line">        set&lt;A*,Comp&gt; ct;</div><div class="line">        while( t -- ) &#123;</div><div class="line">                int n;</div><div class="line">                cin &gt;&gt; n;</div><div class="line">                ct.clear();</div><div class="line">                for( int i = 0;i &lt; n; ++i)	&#123;</div><div class="line">                        char c; int k;</div><div class="line">                        cin &gt;&gt; c &gt;&gt; k;</div><div class="line"></div><div class="line">                        if( c == &apos;A&apos;)</div><div class="line">                                ct.insert(new A(k));</div><div class="line">                        else</div><div class="line">                                ct.insert(new B(k));</div><div class="line">                &#125;</div><div class="line">                for_each(ct.begin(),ct.end(),Print);</div><div class="line">                cout &lt;&lt; &quot;****&quot; &lt;&lt; endl;</div><div class="line">        &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div></pre></td><td class="code"><pre><div class="line">输入</div><div class="line"></div><div class="line">第一行是整数t,表明一共t组数据. t &lt; 20</div><div class="line"></div><div class="line">对每组数据：</div><div class="line"></div><div class="line">第一行是整数n,表示下面一共有n行。 0 &lt; n &lt; 100</div><div class="line"></div><div class="line">下面的每行代表一个人。每行以一个字母开头，代表该人所属的类别，然后跟着一个整数，代表年龄。字母只会是 &apos;A‘或‘B&apos; 。整数范围0到100。数据保证年龄都不相同。</div><div class="line"></div><div class="line">输出</div><div class="line"></div><div class="line">对每组输入数据，将这些人按年龄从小到大输出。每个人先输出类别，再输出年龄。每组数据的末尾加一行 &quot;****&quot;</div><div class="line"></div><div class="line">样例输入</div><div class="line"></div><div class="line">2</div><div class="line">4</div><div class="line">A 3</div><div class="line">B 4</div><div class="line">A 5</div><div class="line">B 6</div><div class="line">3</div><div class="line">A 4</div><div class="line">A 3</div><div class="line">A 2</div><div class="line">样例输出</div><div class="line"></div><div class="line">A 3</div><div class="line">B 4</div><div class="line">A 5</div><div class="line">B 6</div><div class="line">****</div><div class="line">A 2</div><div class="line">A 3</div><div class="line">A 4</div><div class="line">****</div></pre></td></tr></table></figure>
<h2 id="代码-7"><a href="#代码-7" class="headerlink" title="代码"></a>代码</h2><p>B是A的子类。。。一开始没有想到这一点。comp是比较函数。。。。纳闷半天<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line">class A &#123;</div><div class="line">public:</div><div class="line">	int age;</div><div class="line">	string s;</div><div class="line">	A(int a) :age(a), s(&quot;A&quot;) &#123;&#125;</div><div class="line">	A(int a, string str) :age(a), s(str) &#123;&#125;</div><div class="line">&#125;;</div><div class="line"></div><div class="line">class B :public A &#123;</div><div class="line">public:</div><div class="line">	B(int b) :A(b, &quot;B&quot;) &#123;&#125;</div><div class="line">&#125;;</div><div class="line"></div><div class="line">struct Comp &#123;</div><div class="line">	bool operator()(const A* a1, const A* a2) const &#123;</div><div class="line">		return a1-&gt;age &lt; a2-&gt;age;</div><div class="line">	&#125;</div><div class="line">&#125;;</div><div class="line"></div><div class="line">void Print(const A *a) &#123;</div><div class="line">	string t = a-&gt;s;</div><div class="line">	cout &lt;&lt; t.c_str() &lt;&lt; &quot; &quot; &lt;&lt; a-&gt;age &lt;&lt; endl;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<h1 id="编程题＃10：输出指定结果二"><a href="#编程题＃10：输出指定结果二" class="headerlink" title="编程题＃10：输出指定结果二"></a>编程题＃10：输出指定结果二</h1><p>来源: 北京大学在线程序评测系统POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>总时间限制: 1000ms 内存限制: 1024kB</p>
<p>描述</p>
<p>通过填空使得程序输出的结果符合下面的要求。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line">#include &lt;iostream&gt;</div><div class="line">#include &lt;map&gt;</div><div class="line">using namespace std;</div><div class="line">// 在此处补充你的代码</div><div class="line">int A::count = 0;</div><div class="line">void func(B b) &#123; &#125;</div><div class="line">int main()</div><div class="line">&#123;</div><div class="line">        A a1(5),a2;</div><div class="line">        cout &lt;&lt; A::count &lt;&lt; endl;</div><div class="line">        B b1(4);</div><div class="line">        cout &lt;&lt; A::count &lt;&lt; endl;</div><div class="line">        func(b1);</div><div class="line">        cout &lt;&lt; A::count &lt;&lt; endl;</div><div class="line">        A * pa = new B(4);</div><div class="line">        cout &lt;&lt; A::count &lt;&lt; endl;</div><div class="line">        delete pa;</div><div class="line">        cout &lt;&lt; A::count &lt;&lt; endl;</div><div class="line">        return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div></pre></td><td class="code"><pre><div class="line">输入</div><div class="line"></div><div class="line">不需要输入。</div><div class="line"></div><div class="line">输出</div><div class="line"></div><div class="line">使得程序的输出结果是：</div><div class="line"></div><div class="line">2</div><div class="line"></div><div class="line">3</div><div class="line"></div><div class="line">B::destructor</div><div class="line"></div><div class="line">A::destructor</div><div class="line"></div><div class="line">3</div><div class="line"></div><div class="line">4</div><div class="line"></div><div class="line">B::destructor</div><div class="line"></div><div class="line">A::destructor</div><div class="line"></div><div class="line">3</div><div class="line"></div><div class="line">B::destructor</div><div class="line"></div><div class="line">A::destructor</div><div class="line"></div><div class="line">A::destructor</div><div class="line"></div><div class="line">A::destructor</div><div class="line"></div><div class="line">样例输入</div><div class="line"></div><div class="line">不需要输入。</div><div class="line">样例输出</div><div class="line"></div><div class="line">2</div><div class="line">3</div><div class="line">B::destructor</div><div class="line">A::destructor</div><div class="line">3</div><div class="line">4</div><div class="line">B::destructor</div><div class="line">A::destructor</div><div class="line">3</div><div class="line">B::destructor</div><div class="line">A::destructor</div><div class="line">A::destructor</div><div class="line">A::destructor</div></pre></td></tr></table></figure>
<p>提示</p>
<p>int A::count = 0; 这个变量是用来记录一共有多少个类A及类A的派生类的对象的。</p>
<h2 id="代码-8"><a href="#代码-8" class="headerlink" title="代码"></a>代码</h2><p>考察虚函数。哎，有时间再回头仔细复习下c++。虚函数学过去就忘啊。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">class A &#123;</div><div class="line">public:</div><div class="line">	static int count;</div><div class="line">	</div><div class="line">	A()&#123; A::count++; &#125;</div><div class="line">	A(int t)&#123;</div><div class="line">		A::count++;</div><div class="line">	&#125;</div><div class="line">	virtual ~A()</div><div class="line">	&#123;</div><div class="line">		A::count--;</div><div class="line">		cout &lt;&lt; &quot;A::destructor&quot; &lt;&lt; endl;</div><div class="line">	&#125;</div><div class="line">&#125;;</div><div class="line">class B :public A &#123;</div><div class="line">public:</div><div class="line">	B():A()&#123;&#125;</div><div class="line">	B(int t):A(t)&#123;&#125;</div><div class="line">	B(const B &amp;t):A()&#123;&#125;</div><div class="line">	virtual ~B() &#123;</div><div class="line">		cout &lt;&lt; &quot;B::destructor&quot; &lt;&lt; endl;</div><div class="line">	&#125;</div><div class="line">&#125;;</div></pre></td></tr></table></figure></p>
<h1 id="编程题＃11：数据库内的学生信息"><a href="#编程题＃11：数据库内的学生信息" class="headerlink" title="编程题＃11：数据库内的学生信息"></a>编程题＃11：数据库内的学生信息</h1><p>描述</p>
<p>程序填空，使得下面的程序,先输出</p>
<p>(Tom,80),(Tom,70),(Jone,90),(Jack,70),(Alice,100),</p>
<p>(Tom,78),(Tom,78),(Jone,90),(Jack,70),(Alice,100),</p>
<p>(70,Jack),(70,Tom),(80,Tom),(90,Jone),(100,Alice),</p>
<p>(70,Error),(70,Error),(80,Tom),(90,Jone),(100,Alice),</p>
<hr>
<p>然后，再根据输入数据按要求产生输出数据<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div></pre></td><td class="code"><pre><div class="line">#include &lt;iostream&gt;</div><div class="line">#include &lt;string&gt;</div><div class="line">#include &lt;map&gt;</div><div class="line">#include &lt;iterator&gt;</div><div class="line">#include &lt;algorithm&gt;</div><div class="line">using namespace std;</div><div class="line">// 在此处补充你的代码</div><div class="line">struct Student</div><div class="line">&#123;</div><div class="line">        string name;</div><div class="line">        int score;</div><div class="line">&#125;;</div><div class="line">template &lt;class T&gt;</div><div class="line">void Print(T first,T last) &#123;</div><div class="line">        for(;first!= last; ++ first)</div><div class="line">                cout &lt;&lt; * first &lt;&lt; &quot;,&quot;;</div><div class="line">        cout &lt;&lt; endl;</div><div class="line">&#125;</div><div class="line">int main()</div><div class="line">&#123;</div><div class="line"></div><div class="line">        Student s[] = &#123; &#123;&quot;Tom&quot;,80&#125;,&#123;&quot;Jack&quot;,70&#125;,</div><div class="line">                                        &#123;&quot;Jone&quot;,90&#125;,&#123;&quot;Tom&quot;,70&#125;,&#123;&quot;Alice&quot;,100&#125; &#125;;</div><div class="line">        MyMultimap&lt;string,int&gt; mp;</div><div class="line">        for(int i = 0; i&lt;5; ++ i)</div><div class="line">                mp.insert(make_pair(s[i].name,s[i].score));</div><div class="line">        Print(mp.begin(),mp.end()); //按姓名从大到小输出</div><div class="line"></div><div class="line">        mp.Set(&quot;Tom&quot;,78); //把所有名为&quot;Tom&quot;的学生的成绩都设置为78</div><div class="line">        Print(mp.begin(),mp.end());</div><div class="line"></div><div class="line"></div><div class="line">        MyMultimap&lt;int,string,less&lt;int&gt; &gt; mp2;</div><div class="line">        for(int i = 0; i&lt;5; ++ i)</div><div class="line">                mp2.insert(make_pair(s[i].score,s[i].name));</div><div class="line"></div><div class="line">        Print(mp2.begin(),mp2.end()); //按成绩从小到大输出</div><div class="line">        mp2.Set(70,&quot;Error&quot;);          //把所有成绩为70的学生，名字都改为&quot;Error&quot;</div><div class="line">        Print(mp2.begin(),mp2.end());</div><div class="line">        cout &lt;&lt; &quot;******&quot; &lt;&lt; endl;</div><div class="line"></div><div class="line">        mp.clear();</div><div class="line">        </div><div class="line">        string name;</div><div class="line">        string cmd;</div><div class="line">        int score;</div><div class="line">        while(cin &gt;&gt; cmd ) &#123;</div><div class="line">                if( cmd == &quot;A&quot;) &#123;</div><div class="line">                        cin &gt;&gt; name &gt;&gt; score;</div><div class="line">                        if(mp.find(name) != mp.end() ) &#123;</div><div class="line">                                cout &lt;&lt; &quot;erroe&quot; &lt;&lt; endl;</div><div class="line">                        &#125;</div><div class="line">                        mp.insert(make_pair(name,score));</div><div class="line">                &#125;</div><div class="line">                else if(cmd == &quot;Q&quot;) &#123;</div><div class="line">                        cin &gt;&gt; name;</div><div class="line">                        MyMultimap&lt;string,int&gt;::iterator p = mp.find(name);</div><div class="line">                        if( p!= mp.end()) &#123;</div><div class="line">                                cout &lt;&lt; p-&gt;second &lt;&lt; endl;</div><div class="line">                        &#125;</div><div class="line">                        else &#123;</div><div class="line">                                cout &lt;&lt; &quot;Not Found&quot; &lt;&lt; endl;</div><div class="line">                        &#125;</div><div class="line">                &#125;</div><div class="line">        &#125;</div><div class="line">        return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div></pre></td><td class="code"><pre><div class="line">输入</div><div class="line"></div><div class="line">输入数据的每一行，格式为以下之一：</div><div class="line"></div><div class="line">A name score</div><div class="line"></div><div class="line">Q name score</div><div class="line"></div><div class="line">name是个不带个空格的字符串，长度小于 20</div><div class="line"></div><div class="line">score是个整数，能用int表示</div><div class="line"></div><div class="line">A name score 表示往数据库中新增一个姓名为name的学生，其分数为score。开始时数据库中一个学生也没有。</div><div class="line"></div><div class="line">Q name 表示在数据库中查询姓名为name的学生的分数</div><div class="line"></div><div class="line">数据保证学生不重名。</div><div class="line"></div><div class="line">输入数据少于200,000行。</div><div class="line"></div><div class="line">输出</div><div class="line"></div><div class="line">对于每个查询，输出学生的分数。如果查不到，则输出 &quot;Not Found&quot;</div><div class="line"></div><div class="line">样例输入</div><div class="line"></div><div class="line">A Tom1 30</div><div class="line">A Tom2 40</div><div class="line">Q Tom3</div><div class="line">A Tom4 89</div><div class="line">Q Tom1</div><div class="line">Q Tom2</div><div class="line">样例输出</div><div class="line"></div><div class="line">(Tom,80),(Tom,70),(Jone,90),(Jack,70),(Alice,100),</div><div class="line">(Tom,78),(Tom,78),(Jone,90),(Jack,70),(Alice,100),</div><div class="line">(70,Jack),(70,Tom),(80,Tom),(90,Jone),(100,Alice),</div><div class="line">(70,Error),(70,Error),(80,Tom),(90,Jone),(100,Alice),</div><div class="line">******</div><div class="line">Not Found</div><div class="line">30</div><div class="line">40</div></pre></td></tr></table></figure>
<p>提示</p>
<p>1) 编写模板的时候，连续的两个 “&gt;”最好要用空格分开，以免被编译器看作是 “&gt;&gt;”运算符。VS可能无此问题，但是Dev C++和服务器上的编译环境会有这个问题。</p>
<p>比如 vector<vector<int>&gt; 有可能出错，要改成 vector<vector<int> &gt;</vector<int></vector<int></p>
<p>2) 在模板中写迭代器时，最好在前面加上 typename关键字，否则可能会编译错。VS可能无此问题，但是Dev C++和服务器上的编译环境会有这个问题。</p>
<h2 id="代码-9"><a href="#代码-9" class="headerlink" title="代码"></a>代码</h2><p>居然让实现一个Multimap。。。。<br>此题不会，日后再做。。。</p>

      
    </div>
    
  </div>
  
    
    <div class="copyright">
        <p><span>本文标题:</span><a href="/2016/01/27/coursera_c++期末考试/">coursera_c++期末考试</a></p>
        <p><span>文章作者:</span><a href="/" title="回到主页">Bingo</a></p>
        <p><span>发布时间:</span>2016-01-27, 10:40:52</p>
        <p><span>最后更新:</span>2016-01-27, 10:56:25</p>
        <p>
            <span>原始链接:</span><a class="post-url" href="/2016/01/27/coursera_c++期末考试/" title="coursera_c++期末考试">http://blog.acbingo.cn/2016/01/27/coursera_c++期末考试/</a>
            <span class="copy-path" data-clipboard-text="原文: http://blog.acbingo.cn/2016/01/27/coursera_c++期末考试/　　作者: Bingo" title="点击复制文章链接"><i class="fa fa-clipboard"></i></span>
            <script> var clipboard = new Clipboard('.copy-path'); </script>
        </p>
        <p>
            <span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" title="CC BY-NC-SA 4.0 International" target = "_blank">"署名-非商用-相同方式共享 4.0"</a> 转载请保留原文链接及作者。
        </p>
    </div>



    <nav id="article-nav">
        
            <div id="article-nav-newer" class="article-nav-title">
                <a href="/2016/01/27/coursera_c++高级主体和c++11新特性/">
                    coursera_c++高级主体和c++11新特性
                </a>
            </div>
        
        
            <div id="article-nav-older" class="article-nav-title">
                <a href="/2016/01/24/coursera_STL2作业/">
                    coursera_STL2作业
                </a>
            </div>
        
    </nav>

  
</article>

    <div id="toc" class="toc-article">
        <strong class="toc-title">文章目录</strong>
        
            <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃1：输出200"><span class="toc-number">1.</span> <span class="toc-text">编程题＃1：输出200</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#代码"><span class="toc-number">1.1.</span> <span class="toc-text">代码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃2：输出指定结果一"><span class="toc-number">2.</span> <span class="toc-text">编程题＃2：输出指定结果一</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#代码-1"><span class="toc-number">2.1.</span> <span class="toc-text">代码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃3：计算数列平方和"><span class="toc-number">3.</span> <span class="toc-text">编程题＃3：计算数列平方和</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#代码-2"><span class="toc-number">3.1.</span> <span class="toc-text">代码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃4：计算整数平方和"><span class="toc-number">4.</span> <span class="toc-text">编程题＃4：计算整数平方和</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#代码-3"><span class="toc-number">4.1.</span> <span class="toc-text">代码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃5：计算数组的低3位之和"><span class="toc-number">5.</span> <span class="toc-text">编程题＃5：计算数组的低3位之和</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃6：MyString"><span class="toc-number">6.</span> <span class="toc-text">编程题＃6：MyString</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#代码-4"><span class="toc-number">6.1.</span> <span class="toc-text">代码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃7：字符串排序"><span class="toc-number">7.</span> <span class="toc-text">编程题＃7：字符串排序</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#代码-5"><span class="toc-number">7.1.</span> <span class="toc-text">代码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃8：计算整数k"><span class="toc-number">8.</span> <span class="toc-text">编程题＃8：计算整数k</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#代码-6"><span class="toc-number">8.1.</span> <span class="toc-text">代码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃9：人群的排序和分类"><span class="toc-number">9.</span> <span class="toc-text">编程题＃9：人群的排序和分类</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#代码-7"><span class="toc-number">9.1.</span> <span class="toc-text">代码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃10：输出指定结果二"><span class="toc-number">10.</span> <span class="toc-text">编程题＃10：输出指定结果二</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#代码-8"><span class="toc-number">10.1.</span> <span class="toc-text">代码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃11：数据库内的学生信息"><span class="toc-number">11.</span> <span class="toc-text">编程题＃11：数据库内的学生信息</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#代码-9"><span class="toc-number">11.1.</span> <span class="toc-text">代码</span></a></li></ol></li></ol>
        
    </div>
    <style>
        .left-col .switch-btn,
        .left-col .switch-area {
            display: none;
        }
        .toc-level-3 i,
        .toc-level-3 ol {
            display: none !important;
        }
    </style>

    <input type="button" id="tocButton" value="隐藏目录"  title="点击按钮隐藏或者显示文章目录">

    <script>
        yiliaConfig.toc = ["隐藏目录", "显示目录", !!"false"];
    </script>



    
<div class="share">
    
        <div class="bdsharebuttonbox">
            <a href="#" class="fa fa-twitter bds_twi" data-cmd="twi" title="分享到推特"></a>
            <a href="#" class="fa fa-weibo bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
            <a href="#" class="fa fa-qq bds_sqq" data-cmd="sqq" title="分享给 QQ 好友"></a>
            <a href="#" class="fa fa-files-o bds_copy" data-cmd="copy" title="复制网址"></a>
            <a href="#" class="fa fa fa-envelope-o bds_mail" data-cmd="mail" title="通过邮件分享"></a>
            <a href="#" class="fa fa-weixin bds_weixin" data-cmd="weixin" title="生成文章二维码"></a>
            <a href="#" class="fa fa-share-alt bds_more" data-cmd="more"></i></a>
        </div>
        <script>
            window._bd_share_config={
                "common":{"bdSnsKey":{},"bdText":"coursera_c++期末考试　| Bingo's Blog　","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
        </script>
    

    
</div>







    
      <div class="duoshuo" id="comments">
    <div id="comment-box" ></div>
    <div class="ds-thread" id="ds-thread" data-thread-key="2016/01/27/coursera_c++期末考试/" data-title="coursera_c++期末考试" data-url="http://blog.acbingo.cn/2016/01/27/coursera_c++期末考试/"></div>
    <script>
        var duoshuoQuery = {short_name:"acbingo"};
        var loadComment = function(){
            var d = document, s = d.createElement('script');
            s.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
            s.async = true; s.charset = 'UTF-8';
            (d.head || d.body).appendChild(s);
        }

        
    </script>
    
    <script> loadComment(); </script>

</div>
    




    <div class="scroll" id="post-nav-button">
        
            <a href="/2016/01/27/coursera_c++高级主体和c++11新特性/" title="上一篇: coursera_c++高级主体和c++11新特性">
                <i class="fa fa-angle-left"></i>
            </a>
        

        <a title="文章列表"><i class="fa fa-bars"></i><i class="fa fa-times"></i></a>

        
            <a href="/2016/01/24/coursera_STL2作业/" title="下一篇: coursera_STL2作业">
                <i class="fa fa-angle-right"></i>
            </a>
        
    </div>

    <ul class="post-list"><li class="post-list-item"><a class="post-list-link" href="/2016/08/07/c++初始化列表/">c++初始化列表</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/08/05/一步一步学习红黑树-2/">一步一步学习红黑树-2</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/08/04/一步一步学习红黑树/">一步一步学习红黑树-1</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/08/03/回文解码/">回文解码</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/08/03/C++中虚析构函数的作用/">C++中虚析构函数的作用</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/08/03/const/">const</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/08/03/const与常成员函数/">const与常成员函数</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/31/虚拟继承/">虚拟继承</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/31/函数指针/">函数指针</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/28/记事本/">记事本</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/28/StarFiles/">StarFiles</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/28/酒店管理系统/">酒店管理系统</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/28/飞机大战/">飞机大战</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/27/仿函数/">仿函数/函数对象</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/27/二叉树中和为某一值的路径/">二叉树中和为某一值的路径</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/26/递归实现反转列表/">递归实现反转链表</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/26/快速幂/">快速幂</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/26/bitset的用法/">bitset的用法</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/26/二分查找、归并排序和快速排序/">二分查找、归并排序和快速排序</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/25/重建二叉树/">重建二叉树</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/25/leetcode_5/">LeetCode_5:Longest Palindromic Substring</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/24/leetcode_4/">LeetCode_4:Median of Two Sorted Arrays</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/24/leetcode_3/">LeetCode_3:Longest Substring Without Repeating Characters</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/24/leetcode_2/">LeetCode_2:Add Two Numbers</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/24/leetcode_1_Two Sum/">LeetCode_1:Two Sum</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/06/07/Bingo's_ShadowSocks使用说明/">Bingo's_Shadowsocks</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/05/03/如何优雅的开启wifi热点/">如何优雅的开启wifi热点</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/05/02/如何优雅的连接指定wifi热点/">如何优雅的连接指定wifi热点</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/05/02/对AndroidWifi状态广播的研究/">对AndroidWifi状态广播的研究</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/05/01/coursera数据结构_字符串_课后作业/">coursera数据结构_字符串_课后作业</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/05/01/简单几步在Android_Studio上实现二维码的扫描/">简单几步在Android_Studio上实现二维码的生成与扫描</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/25/coursera_算法课后习题/">coursera_算法课后习题</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/25/coursera_计算机组成学习笔记/">coursera_计算机组成学习笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/20/cocos2dx-飞机大战/">cocos2dx-飞机大战</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/14/android_ping不通电脑/">android_ping不通电脑</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/14/android创建与连接热点/">android创建与连接热点</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/01/coursera_算法_递归/">coursera_算法_递归</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/30/coursera_操作系统学习笔记/">coursera_操作系统学习笔记_计算机操作系统概述</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/29/编译原理_中科大公开课_第一单元编译器介绍作业/">编译原理_中科大公开课_第一单元编译器介绍作业</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/25/关于Inflater与findViewById()的思考/">关于Inflater与findViewById()的思考</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/11/coursera_魔兽世界终结版/">coursera_魔兽世界终结版</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/05/coursera_算法作业_枚举/">coursera_算法作业_枚举</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/27/coursera_c++高级主体和c++11新特性/">coursera_c++高级主体和c++11新特性</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/27/coursera_c++期末考试/">coursera_c++期末考试</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/24/coursera_STL2作业/">coursera_STL2作业</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/21/coursera容器适配器/">coursera容器适配器_算法</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/21/coursera标准模版库STL2/">coursera标准模版库STL2</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/20/coursera编程作业-STL1/">coursera编程作业-STL1</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/20/coursera疑问/">coursera疑问</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/19/coursera学习笔记-函数对象/">coursera学习笔记-函数对象</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/19/coursera学习笔记-顺序容器Vector/">coursera学习笔记-顺序容器Vector、List和Deque</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/05/算法学习笔记-14-最长公共子序列/">算法学习笔记-14-最长公共子序列</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/03/算法学习笔记-13-矩阵连乘问题/">算法学习笔记-13-矩阵连乘问题</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/01/算法学习笔记-12-循环赛日程表/">算法学习笔记-12-循环赛日程表</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/01/算法学习笔记-11-最接近点对问题/">算法学习笔记-11-最接近点对问题</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/01/算法学习笔记-10-线性时间选择/">算法学习笔记-10-线性时间选择</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/27/算法学习笔记-9-快速排序/">算法学习笔记-9-快速排序</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/26/算法学习笔记-8-合并排序/">算法学习笔记-8-归并排序</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/24/算法学习笔记-7-棋盘覆盖问题/">算法学习笔记-7-棋盘覆盖问题</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/22/算法学习笔记-6-Strassen矩阵乘法/">算法学习笔记-6-Strassen矩阵乘法</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/21/算法学习笔记-5-Hanoi塔问题/">算法学习笔记-5-Hanoi塔问题</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/20/算法学习笔记-4-整数划分问题/">算法学习笔记-4-整数划分问题</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/19/算法学习笔记-3-排列问题/">算法学习笔记-3-排列问题</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/18/算法学习笔记-2-递归的概念/">算法学习笔记-2-递归的概念</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/17/coursera_标准模板库STL/">coursera_标准模板库STL</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/17/算法学习笔记-0-序/">算法学习笔记-0-序</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/17/算法学习笔记-1-NP完全性理论/">算法学习笔记-1-NP完全性理论</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/14/文件操作和模板_编程作业/">文件操作和模板_编程作业</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/11/ubuntu下安装最新的nodejs(v4.2.2)/">ubuntu下安装最新的nodejs(v4.2.2)</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/11/ubuntu14.04的环境变量/">ubuntu14.04的环境变量</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/01/coursera学习笔记_文件操作和模板/">coursera学习笔记_文件操作和模板</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/10/31/coursera学习笔记_多态和虚函数/">coursera学习笔记_多态和虚函数</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/10/28/Coursera_程序设计与晋级_继承与派生_编程作业/">Coursera_程序设计与晋级_继承与派生_编程作业</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/10/22/科大OJ-数据结构-DNA序列/">科大OJ-数据结构-DNA序列</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/10/20/科大OJ-数据结构-求表达式串的后缀表达式和值/">科大OJ-数据结构-求表达式串的后缀表达式和值</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/10/01/科大OJ-数据结构-击鼓传花/">科大OJ-数据结构-击鼓传花</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/30/科大OJ-数据结构-求集合的交并补集/">科大OJ-数据结构-求集合的交并补集</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/27/hexo无法本地访问/">hexo无法本地访问</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/26/继承与派生/">coursera学习笔记_继承与派生</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/26/大数类模板/">大数类模板</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/15/vimium学习笔记/">vimium学习笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/04/程序员矩阵/">程序员矩阵</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/03/coursera学习笔记_运算符重载/">coursera学习笔记_运算符重载</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/01/写hexo博客、markdown文章时图床的挑选/">写hexo博客、markdown文章时图床的挑选</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/31/coursera学习笔记-c++程序设计/">coursera学习笔记-c++程序设计</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/29/Linux下C语言应用编程学习笔记/">Linux下C语言应用编程学习笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/28/linux学习笔记2/">linux学习笔记2</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/27/Bingo's exVim/">Bingo的VIM</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/27/linux下去掉^M的方法/">linux下去掉^M的方法</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/27/vim的持久撤销功能/">vim的持久撤销功能</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/25/linux学习笔记/">linux学习笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/18/线段树学习笔记-7-hdu1698/">线段树学习笔记-7-hdu1698</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/18/线段树学习笔记-6-区间更新/">线段树学习笔记-6-区间更新</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/18/Coursera_程序设计与算法_C程序设计进阶/">Coursera_程序设计与算法_C程序设计进阶</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/18/线段树学习笔记-5-hdu2795/">线段树学习笔记-5-hdu2795</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/14/线段树学习笔记-4-hdu1394/">线段树学习笔记-4-hdu1394</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/14/求逆序对的个数/">求逆序对的个数</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/14/线段树学习笔记-3-hdu1754/">线段树学习笔记-3-hdu1754</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/13/线段树学习笔记-2-hdu1166/">线段树学习笔记-2-hdu1166</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/13/线段树学习笔记/">线段树学习笔记-1-入门</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/11/Coursera_程序设计与算法_计算导论与C语言基础_期末编程测试/">Coursera_程序设计与算法_计算导论与C语言基础_期末编程测试</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/10/Coursera_程序设计与算法_C程序设计进阶_C程序中的函数/">Coursera_程序设计与算法_计算导论与C语言基础_数组应用练习</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/10/Coursera_程序设计与算法_计算导论与C语言基础_数组应用练习/">Coursera_程序设计与算法_计算导论与C语言基础_数组应用练习</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/10/hdu4821 String/">hdu4821 String</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/09/Rolling Hash(Rabin-Karp算法)匹配字符串/">Rolling Hash(Rabin-Karp算法)匹配字符串</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/09/设置vim的默认工作路径/">设置vim的默认工作路径</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/08/滑动窗口的单调队列/">滑动窗口的单调队列</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/08/ssh -T git@github.com出现Permission denied (publickey)/">ssh -T git@github.com出现Permission denied (publickey)</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/05/29/UVa10791-Minimum-Sum-LCM/">UVa10791-Minimum Sum LCM</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/05/29/uva100/">uva100</a></li></ul>




    <script>
        
    </script>
</div>
      <footer id="footer">
    <div class="outer">
        <div id="footer-info">
            <div class="footer-left">
                <i class="fa fa-copyright"></i> 
                2014-2016 Bingo
            </div>
            <div class="footer-right">
                <a href="http://hexo.io/" target="_blank" title="快速、简洁且高效的博客框架">Hexo</a>  Theme <a href="https://github.com/MOxFIVE/hexo-theme-yelee" target="_blank" title="简而不减 Hexo 双栏博客主题  v3.5">Yelee</a> by MOxFIVE <i class="fa fa-heart animated infinite pulse"></i>
            </div>
        </div>
        
            <div class="visit">
                
                    <span id="busuanzi_container_site_pv" style='display:none'>
                        <span id="site-visit" title="本站到访数"><i class="fa fa-user" aria-hidden="true"></i><span id="busuanzi_value_site_uv"></span>
                        </span>
                    </span>
                
                
                    <span>| </span>
                
                
                    <span id="busuanzi_container_page_pv" style='display:none'>
                        <span id="page-visit"  title="本页阅读量"><i class="fa fa-eye animated infinite pulse" aria-hidden="true"></i><span id="busuanzi_value_page_pv"></span>
                        </span>
                    </span>
                
            </div>
        
    </div>
</footer>
    </div>
    
<script data-main="/js/main.js" src="//cdn.bootcss.com/require.js/2.2.0/require.min.js"></script>





<div class="scroll" id="scroll">
    <a href="#" title="返回顶部"><i class="fa fa-arrow-up"></i></a>
    <a href="#comments" onclick="load$hide();" title="查看评论"><i class="fa fa-comments-o"></i></a>
    <a href="#footer" title="转到底部"><i class="fa fa-arrow-down"></i></a>
</div>
<script>
    // Open in New Window
    
        var oOpenInNew = {
            
            
            
            
            
            
             archives: ".archive-article-title", 
             miniArchives: "a.post-list-link", 
            
             friends: "#js-friends a", 
             socail: ".social a" 
        }
        for (var x in oOpenInNew) {
            $(oOpenInNew[x]).attr("target", "_blank");
        }
    
</script>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>
  </div>
</body>
</html>